package com.czk.utils;

import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.MethodVisitor;

import static org.objectweb.asm.Opcodes.*;

/**
 * @Author:ChenZhangKun
 * @Date: 2021/9/22 16:16
 */
public class GenerateInit {
    public static void generateInit(ClassWriter cw) {
        MethodVisitor methodVisitor = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
        // 开始访问代码
        methodVisitor.visitCode();
        // 加载第一个this
        methodVisitor.visitVarInsn(ALOAD, 0);
        // 执行构造
        methodVisitor.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false);
        // 返回
        methodVisitor.visitInsn(RETURN);
        methodVisitor.visitMaxs(0, 0);
        // 结束
        methodVisitor.visitEnd();
    }
}
